Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GA4 event data on taxon pages #3896

Merged
merged 1 commit into from
Dec 10, 2024
Merged

Conversation

MartinJJones
Copy link
Contributor

@MartinJJones MartinJJones commented Dec 9, 2024

What

Set disable_ga4 to true for the document-list component used to render each section on a taxon page.

Why

This fixes an issue on taxon pages (/education for example), where link clicks would fire 2 events instead of 1, both of which were missing some data.

Event data changes

The data below is sent to GA after clicking the "Student finance for undergraduates" link on this page - https://www.gov.uk/education/funding-and-finance-for-students#/education/student-grants-bursaries-scholarships

Before

{
 "event": "event_data",
 "event_data": {
  "event_name": "navigation",
  "external": "false",
  "index": {
   "index_link": "2"
  },
  "link_domain": "https://www.gov.uk",
  "method": "command/win click",
  "text": "Student finance for undergraduates",
  "type": "document list",
  "url": "/student-finance"
 },
 "govuk_gem_version": "46.2.0",
 "timestamp": "1733824170576"
}

{
 "event": "event_data",
 "event_data": {
  "event_name": "navigation",
  "external": "false",
  "index": {
   "index_link": "2"
  },
  "link_domain": "https://www.gov.uk",
  "method": "command/win click",
  "text": "Student finance for undergraduates",
  "type": "document list",
  "url": "/student-finance"
 },
 "govuk_gem_version": "46.2.0",
 "timestamp": "1733824170581"
}

After

Only 1 event is fired and information for "index_section", "index_section_count" and "section" is now included.

{
 "event": "event_data",
 "event_data": {
  "event_name": "navigation",
  "external": "false",
  "index": {
   "index_link": "2",
   "index_section": "1",
   "index_section_count": "8"
  },
  "index_total": "6",
  "link_domain": "https://www.gov.uk",
  "method": "command/win click",
  "section": "Services",
  "text": "Student finance for undergraduates",
  "type": "document list",
  "url": "/student-finance"
 },
 "govuk_gem_version": "46.2.0",
 "timestamp": "1733824112924"
}

@govuk-ci govuk-ci temporarily deployed to collections-pr-3896 December 9, 2024 16:58 Inactive
@MartinJJones MartinJJones marked this pull request as ready for review December 10, 2024 10:51
@@ -62,7 +62,7 @@
}
%>
<%= content_tag(:div, data: ga4_data) do %>
<%= render(partial: section[:partial_template], locals: { section: section }) %>
<%= render(partial: section[:partial_template], locals: { section: section, disable_ga4: true }) %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting a false default into the partials seems sensible, but is there a situation where that isn't overridden by this line?

Copy link
Contributor Author

@MartinJJones MartinJJones Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not see any other uses of the section partials outside of the taxon page where the change is required.

My initial option was to hardcode disable_ga4: true in each section partial, happy to go with this approach if preferred

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that might be simpler - otherwise it implies that this is necessary because some other part of the code doesn't pass true, which isn't correct. We can always extend it later if needed 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, thanks Andy, I've made this change

Set `disable_ga4` to true for the document-list component used to render each section of the taxon page.

This fixes an issue on taxon pages (/education for example), where link clicks would fire 2 events instead of 1, both of which were missing some event data.
@MartinJJones MartinJJones force-pushed the fix-ga4-duplicate-event branch from 9c01f80 to 3a7aec6 Compare December 10, 2024 12:25
@govuk-ci govuk-ci temporarily deployed to collections-pr-3896 December 10, 2024 12:26 Inactive
@MartinJJones MartinJJones merged commit dca1d5b into main Dec 10, 2024
14 checks passed
@MartinJJones MartinJJones deleted the fix-ga4-duplicate-event branch December 10, 2024 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants